package com.mijie.homi.dao.user;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.common.domain.user.UserExtInfo;

@Repository
public class UserExtInfoDao extends IBatisDao{

	
	public int incrNumOfPhoto(int userId,int size){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId", userId);
		parameter.put("size", size);
		return this.update("incrNumOfPhoto", parameter);
	}
	
	public int incrNumOfRelatedTopic(int userId){
		return this.update("incrNumOfRelatedTopic", userId);
	}
	
	
	public int decrNumOfPhoto(int userId){
		return this.update("decrNumOfPhoto", userId);
	}
	
	public int decrNumOfMood(int userId){
		return this.update("decrNumOfMood", userId);
	}
	
	public int settingMoodAndDecrNumOfMood(int userId,int mood,long moodId){
		Map<String,Object> parameter = new HashMap<String,Object>(3);
		parameter.put("id", userId);
		parameter.put("mood", mood);
		parameter.put("moodId", moodId);
		return this.update("settingMoodAndDecrNumOfMood", parameter);
	}
	
	public UserExtInfo getUserExtInfoByUserId(int userId){
		return this.selectOne("getUserExtInfoByUserId",userId);
	}
	
	public int settingAlbumCover(int userId,String albumCover){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId", userId);
		parameter.put("albumCover", albumCover);
		return this.update("settingAlbumCover", parameter);
	}
	
	
	public int increIntegral(int id,int integral){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("id", id);
		parameter.put("integral", integral);
		return this.update("increIntegral", parameter);
	}
	
	public int createUserExtInfo(UserExtInfo info){
		return this.insert("createUserExtInfo",info);
	}
	
	public int updateLocation(int id,double latitude,double longitude,String ip){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("id", id);
		parameter.put("latitude", latitude);
		parameter.put("longitude", longitude);
		if(ip!=null) parameter.put("ip", ip);
		return this.update("updateLocation", parameter);
	}
	
	public int settingMood(int id,long moodId,int mood){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("id", id);
		parameter.put("moodId", moodId);
		parameter.put("mood", mood);
		parameter.put("date", new Date());
		return this.update("settingMood", parameter);
	}
	
	public List<UserExtInfo> listUserExtInfoByIds(List<Integer> list){
		return this.selectList("listUserExtInfoByIds", list);
	}
	
	public int updateUserDeviceIdAndTerminalId(int userId,String deviceId,String terminalId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId", userId);
		parameter.put("deviceId", deviceId);
		parameter.put("terminalId", terminalId);
		return this.update("updateUserDeviceIdAndTerminalId", parameter);
	}
	
	public int updateSysMsgMarkByUserId(Map<String, Integer> param){
		return this.update("updateSysMsgMarkByUserId", param);
	}
}
